{% extends 'admin/indexBase.html' %}

{% block title %}回收站{% endblock %}

{% block main %}
    <h2 class="sub-header">已删除列表</h2>
    {% if books %}
        <div class="table-responsive">
            <table class="table table-striped">
                <thead class="row">
                <tr>
                    <th class="col-1">#</th>
                    <th class="col-1">书名</th>
                    <th class="col-1">作者</th>
                    <th class="col-lg-5">简介</th>
                    <th class="col-1">价格</th>
                    <th class="col-lg-2"></th>
                    {% for message in get_flashed_messages() %}
                        <th class="col-1 info">错误</th>
                    {% endfor %}
                </tr>
                </thead>
                <tbody>
                {% for book in books %}
                    <tr>
                        <td>{{ loop.index }}</td>
                        <td>{{ book.title }}</td>
                        <td>{{ book.author }}</td>
                        <td>{{ book.subheading }}</td>
                        <td>{{ book.price }}</td>
                        <td>
                            <a type="button" class="btn btn-primary" role="button"
                               href="{{ url_for('bookAdmin.off_shelf_book_trash' , book_id=book['_id']) }}"
                               onclick="javascrip:return confirm('您确定要还原？')">还原</a>
                            <a type="button" class="btn btn-danger" role="button"
                               href="{{ url_for('bookAdmin.trash_delete' , book_id=book['_id']) }}"
                               onclick="javascrip:return confirm('您确定要永久删除？')">永久删除</a>
                        </td>
                        {% for message in get_flashed_messages() %}
                            <td class="flash text-center"><b>{{ message }}</b></td>
                        {% endfor %}
                    </tr>

                {% endfor %}
                </tbody>
            </table>
        </div>
    {% elif users %}
        <div class="table-responsive">
            <table class="table table-striped">
                <thead>
                <tr>
                    <th>#</th>
                    <th>用户名</th>
                    <th>手机号</th>
                    <th>email</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                {% for user in users %}
                    <tr>
                        <td>{{ loop.index }}</td>
                        <td>{% if user.name == None %}{% else %}{{ user.name }}{% endif %}</td>
                        <td>{{ user.tel }}</td>
                        <td>{% if user.email == None %}{% else %}{{ user.email }}{% endif %}</td>
                        <td>
                            <a type="button" class="btn btn-primary" role="button"
                               href="{{ url_for('userAdmin.restores_user' , user_id=user.id) }}"
                               onclick="javascrip:return confirm('您确定要还原？')">还原</a>&nbsp;&nbsp;&nbsp;
                            <button type="button" class="btn btn-danger" onclick="deleteUser('{{ user.id }}')">
                                永久删除
                            </button>
                        </td>
                    </tr>
                {% endfor %}
                </tbody>
            </table>
        </div>
    {% endif %}
                <div id="pages">

    </div>
    <script>
        new Pagination({
            element: '#pages',
            type: 1,
            pageIndex: {{ active_page }},   //默认活动页
            pageSize: {{ page_size }},	//一页数量
            pageCount: {{ page_count }},   //显示页数
            total: {{ total }},      //总数
            jumper: true,
            singlePageHide: false,
            prevText: '上一页',
            nextText: '下一页',
            disabled: false,
            currentChange: function (index) {
                console.log(index);
                //https://blog.csdn.net/pengShuai007/article/details/86528992
                var a = document.createElement('a');
                a.setAttribute('href', '{{ trash_type }}'+index);
                // 防止反复添加
                if (document.getElementById('startTelMedicine')) {
                    document.body.removeChild(document.getElementById('startTelMedicine'));
                }
                document.body.appendChild(a);
                a.click();
            }
        });
    </script>
{% endblock %}